from app import ma
from .models import Like

# 点赞序列化 Schema
class LikeSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Like
        load_instance = True
        # 让Marshmallow自动发现所有字段，避免版本兼容性问题
    
    # 【关键修复】用字符串引用 UserProfileSchema 和 RecipeSimpleSchema，避免直接导入
    user = ma.Nested('app.users.schemas.UserProfileSchema', many=False)
    recipe = ma.Nested('app.recipes.schemas.RecipeSimpleSchema', many=False)

# 实例化序列化器
like_schema = LikeSchema()
likes_schema = LikeSchema(many=True)